#include<stdio.h>
#include<conio.h>

#define max 100
/*
Program for Matrix Operations
By: Owais Lone
    Rollno: 33
    Class: SE-II
    Batch: B
Usage of Variables
Matrices= a[][],b[][],c[][]
Rows & Columns= r1,r2,c1,c2
Switch Case Variable= sw
counters= i,j,k
main loop counter= cond
input check= in
flags= f
*/

void main()
{
int a[max][max],b[max][max],c[max][max],r1,r2,c1,c2,sw,i,j,k,f,cond,in;
clrscr();

for(cond=1;cond!=0;)
{
clrscr();

printf("1:Input Matrix\n2:Add\n3:Subtract\n4:Multiply\n5:Transpose\n6:Symmetric\n7:Skew Symmetric\n8:Exit\n\nFirst Matrix will be used for Transpose, Symmetric & Skew-Symmetric\n\nChoice>>>>");
scanf("%d",&sw);
switch(sw)
{
     case 1:
     {
     clrscr();

     in=1;
printf("Enter the order of First Matrix\nRows=");
scanf("%d",&r1);
printf("Columns=");
scanf("%d",&c1);
clrscr();
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);

printf("\n");
}
}
clrscr();
printf("Enter the order of Second Matrix\nRows=");
scanf("%d",&r2);
printf("Columns=");
scanf("%d",&c2);
clrscr();
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
printf("\n");
}
}
clrscr();
printf("Storing Values");
for(i=0;i<3;i++)
{
printf("\\\b");
delay(100);
printf("|\b");
delay(100);
printf("/\b");
delay(100);
printf("--\b");
delay(100);
printf("\\\b");
delay(100);
printf("|\b");
delay(100);
printf("/\b");
delay(100);
printf("--\b");
}
clrscr();
printf("Values Stored in Memory.....Ready for Operations");
getch();
clrscr();
break;
}


     case 2:
     {
     clrscr();
     if(in==1)
     {
       if(r1==r2&&c1==c2)
       {
	    for(i=1;i<=r1;i++)
	    {
	       for(j=1;j<=c1;j++)
	       {
	       c[i][j]=a[i][j]+b[i][j];
	       }
	    }
	    clrscr();
	    printf("The Addition is\n\n\n\t\t");
	    for(i=1;i<=r1;i++)
	    {
	      for(j=1;j<=c1;j++)
	      printf("%d ",c[i][j]);
	      printf("\n\t\t");
	    }
       }
       else
       {
       clrscr();
       printf("Rows & Columns must be equal for addition");
       }
     }
     else
     printf("Please Enter the Matrix First");
     getch();
     break;
     }

     case 3:
     {
     clrscr();
     if(in==1)
     {
      if(r1==r2&&c1==c2)
       {
	    for(i=1;i<=r1;i++)
	    {
	       for(j=1;j<=c1;j++)
	       {
	       c[i][j]=a[i][j]-b[i][j];
	       }
	    }
	    clrscr();
	    printf("The Subtraction is\n\n\n\t\t");
	    for(i=1;i<=r1;i++)
	    {
	      for(j=1;j<=c1;j++)
	      printf("%d ",c[i][j]);
	      printf("\n\t\t");
	    }
       }
       else
       {
       clrscr();
       printf("Rows & Columns must be equal for subtraction");
       }
       }
       else
       printf("Please enter the Matrix first");
     getch();
      break;
     }

     case 4:
     {
     clrscr();
     if(in==1)
     {
     clrscr();

	if(c1==r2)
	{
	     for(i=1;i<=r1;i++)
	     {
	       for(k=1;k<=r2;k++)
	       {
	       c[i][k]=0;
		  for(j=1;j<=c1;j++)
		  {
		  c[i][k]=(a[i][k]*b[j][k])+c[i][k];
		  }
		}
	     }
	     printf("The Multiplication is\n\n\n\t\t");
	     for(i=1;i<=r1;i++)
	     {
		  for(j=1;j<=c2;j++)
		  {
		  printf("%d ",c[i][j]);
		  }
		  printf("\n\t\t");
	     }
	}
	else
	{
	clrscr();
	printf("Rows of MAtrix 1 must be equal to columns of Matrix 2\n");
	}
	}
    else
    printf("Please enter the matirx");
    getch();
     break;
     }

     case 5:
     { clrscr();
     if(in==1)
     {
	for(i=1;i<=r1;i++)
	{
	   for(j=1;j<=c1;j++)
	   {
	   b[i][j]=a[j][i];
	   }
	}
	printf("Transpose of Matrix is\n\n\t\t");
	 for(i=1;i<=r1;i++)
	    {
	      for(j=1;j<=c1;j++)
	      printf("%d ",b[i][j]);
	      printf("\n\t\t");
	    }
	    }

     else
     printf("Please Enter Matrix First");



     getch();
     break;
     }

     case 6:
     {
     clrscr();
     if(in==1)
     {
	for(i=1;i<=r1;i++)
	{
	   for(j=1;j<=c1;j++)
	   {
	      if(a[i][j]==a[j][i])
	      f=1;

	      else
	      {
	      f=0;
	      break;
	      }
	   }
	   if(f==0)
	   break;
	}
	if(f==1)
	{
	   clrscr();
	   printf("\nThe Matrix is Symmetric");
	getch();
	}
	else if(f==0)
	{
	clrscr();
	printf("\nThe Matrix is not Symmetric");
	getch();
	}
	else
	printf("Please Enter the Matrix Fisrt");

     break;
     }
      case 7:
     {
     clrscr();
     if(in==1)
     {
	for(i=1;i<=r1;i++)
	{
	   for(j=1;j<=c1;j++)
	   {
	   if(i==j)
	   {}
	   else
	   {
	      if(a[i][j]==-a[j][i])
	      f=1;

	      else
	      {
	      f=0;
	      break;
	      }
	   }
	   }
	   if(f==0)
	   break;
	}
	if(f==1)
	{
	   clrscr();
	   printf("\nThe Matrix Skew-Symmetric");
	getch();
	}
	else if(f==0)
	{
	clrscr();
	printf("\nThe Matrix is not Skew-Symmetric");
	getch();
	}
      }
      else
      printf("Please Enter the Matrix First");
     getch();
     break;
     }
     case 8:
     cond=0;
}
}
}
}